#include "thread/lock.h"

namespace renderit
{
	namespace thread
	{
		semaphore::semaphore()
		{
			HANDLE h = ::CreateSemaphore(
				NULL,
				0,
				0xFFFF,
				NULL
			);
			d_ = h;
		}
		semaphore::~semaphore()
		{
			::CloseHandle(d_);
		}

		void semaphore::P()
		{
			::WaitForSingleObject(d_, INFINITE);
		}

		void semaphore::V()
		{
			::ReleaseSemaphore(d_, 1, nullptr);
		}
	}
}